<?php
// 配置阿里云镜像
composer config repo.packagist composer https://mirrors.aliyun.com/composer/

/usr/local/software/php8/bin/php /usr/local/bin/composer install

find ./vendor -name ".gitignore"
// 删除 vendor 目录下的 .gitignore
find ./vendor -name ".gitignore" -delete

// 删除含有.igt 文件
find ./vendor -type d -name ".git" | xargs rm -rf






find  .  -name  '*.exe'  -type  f  -print  -exec  rm  -rf  {} ;


vim .gitignore

/node_modules
Homestead.yaml
Homestead.json
.env
.idea





 git clone git@101.200.221.231:speed-read-website.git


 git remote add origin git@101.200.221.231:speed-read-website.git


cp -R  ../materiel_bak/deploy ./
cp -R  ../materiel_bak/app/Http/Controllers/Admin ./app/Http/Controllers
cp -R  ../materiel_bak/app/Http/Controllers/Web ./app/Http/Controllers
cp -R  ../materiel_bak/app/Http/Controllers/Base ./app/Http/Controllers
cp -R  ../materiel_bak/app/Http/Controllers/Api ./app/Http/Controllers
cp -R  ../materiel_bak/app/Model ./app
cp -R  ../materiel_bak/resources/views/admin ./resources/views
cp -R  ../materiel_bak/resources/views/layout ./resources/views
cat  ../materiel_bak/routes/web.php >  ./routes/web.php 
cat  ../materiel_bak/routes/api.php >  ./routes/api.php
cp -R  ../user_bak/public/static ./public/

cp .env.example .env
# php artisan list
php artisan key:generate
cp .env .env.dev
cp .env .env.production

分页
=============================================================
        // $data = DB::table('news')->orderBy('id', 'desc')->first();
        //  News::create([
        //     // 'title' => 'john@example.com' . ($data->id + 1),
        //     'title' => 'john@example.com' ,
        //     'content' => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa我是新闻'
        // ]);       

        // $data = DB::table('news')->orderBy('id', 'desc')->first();
        // $data = DB::table('news')->orderBy('id', 'desc')->paginate(8);

        $data = News::orderBy('id', 'desc')->paginate();
        // $data->setPath('custom/url');   设置 url
        // $data->appends(['sort' => 'votes'])->render();   // 追加参数
        // $data->appends(['sort' => 'votes']);   // 追加参数
        // $data->fragment('foo')->render();   #  锚连接

        // echo '<pre>';
        // print_r($data);
        // exit;

        // echo '<pre>';
        // foreach ($data as $key => $value) {
        //     print($value->id);
        //     echo '<br>';
        //     print($value->title);
        //     echo '<br>';
        //     print($value->content);
        //     echo '<br>';
        //     print($value->created_at);
        //     echo '<br>';
        //     print($value->updated_at);
        //     echo '<br>';
        // }

        // $nbsp = '&nbsp;&nbsp;&nbsp;&nbsp;';
        // echo '当前查询总数'  . $nbsp . $data->count(); echo '<br>';
        // echo '当前页'  . $nbsp .$data->currentPage(); echo '<br>';
        // echo '下一页是否还有数据'  . $nbsp .$data->hasMorePages(); echo '<br>';
        // echo '最后页'  . $nbsp .$data->lastPage(); echo '<br>';
        // echo '下一页url'  . $nbsp .$data->nextPageUrl(); echo '<br>';
        // echo '分页数量'  . $nbsp .$data->perPage(); echo '<br>';
        // echo '上一页url'  . $nbsp .$data->previousPageUrl(); echo '<br>';
        // echo '总条数'  . $nbsp .$data->total(); echo '<br>';
        // echo '跳转到某一页的url'  . $nbsp .$data->url(4); echo '<br>';
        // print_r($data);
        // exit;
        return view('admin.news.index');

    <div class="row">
        <ul class="pagination pagination-lg">
            @if ($data->previousPageUrl())<!-- 上一页 -->
                <li><a href="{{ $data->url(1) }}">首页</a></li>
                <li><a href="{{ $data->previousPageUrl() }}">&laquo;</a></li>
            @endif
            <?php
                // 起始行数
                if ($data->currentPage()  >= 6) {
                    $start = $data->currentPage() - 5;
                } else {
                    $start = 1;
                }
                // 结束行数
                if ($data->lastPage() - $data->currentPage() >= 6) {
                    $end = $data->currentPage() + 5;
                } else {
                    $end = $data->lastPage();
                }
            ?>
            @for ($i = $start; $i <= $end; $i++)
                @if ($data->currentPage() == $i)
                    <li class="disabled"><a href="{{ $data->url($i) }}">{{ $i }}</a></li>
                @else
                    <li><a href="{{ $data->url($i) }}">{{ $i }}</a></li>
                @endif
            @endfor
            @if ($data->nextPageUrl())<!-- 下一页 -->
                <li><a href="{{ $data->nextPageUrl() }}">&laquo;</a></li>
                <li><a href="{{ $data->url($data->lastPage()) }}">尾页</a></li>
            @endif
            <li>共{{$data->lastPage()}}页  共{{ $data->total() }} 条</li>
        </ul>
    </div>
=============================================================

// class A {
//     public static function  call() {
//         echo 'Class A <br>';
//     }
//     public static function test() {
//         self::call();
//         static::call();
//     }
// }
// class B extends A {
//     public static function call() {
//         echo 'Class B <br>';
//     }
// }
// B::test();



// class A {
//     public function  call() {
//         echo 'instance from  A <br>';
//     }
//     public function test() {
//         self::call();
//         static::call();
//     }
// }
// class B extends A {
//     public function call() {
//         echo 'instance from B <br>';
//     }
// }
// $b = new B();
// $b->test();


// class A {
//     public static function  create() {
//         $self = new self();
//         $static = new static();
//         return array($self, $static);
//     }
// }
// class B extends A {
// }
// $arr = B::create();
// foreach ($arr as $value) {
//    var_dump($value);
// }

// trait 
// abstract

// 装饰者模式
/*interface Decoraror
{
    public function display();
}
class XiaoFang implements Decoraror
{
    private $name;
    public function __construct($name)
    {
        $this->name = $name;
    }
    public function display()
    {
        echo "我是 " . $this->name . " 我出门了<br>";
    }
}
 
class Finery implements Decoraror
{
    private $component;
    public function __construct(Decoraror $component)
    {
        $this->component = $component;
        p($component);
    }
    public function display()
    {
            $this->component->display();
    }
}

class Shoes extends Finery
{
    public function display()
    {
        echo "传上鞋子<br>";
        parent::display();
    }
}
class Skirt extends Finery
{
    public function display()
    {
        echo "穿上裙子<br>";
        parent::display();
    }
}
class Fire extends Finery
{
    public function display()
    {
        echo "出门前先整理头发<br>";
        parent::display();
        echo "出门后在整理一下头发<br>";
    }
}

$xiaofang = new XiaoFang('小芳');
$shoes = new Shoes($xiaofang);
$skirt = new Skirt($shoes);
$fire = new Fire($skirt);
$fire->display();
*/





// 请求处理管道
/*interface Middleware
{
    public static function handle(Closure $next);
}
class VerifyCsrfToken implements Middleware
{
    public static function handle(Closure $next)
    {
        echo "验证 Csrf-Token <br>";
        $next();
    }
}
class ShareErrorsFromSession implements Middleware
{
    public static function handle(Closure $next)
    {
        echo "如果session中有 errors 变量，则共享他<br>";
        $next();
    }
}
class StartSession implements Middleware
{
    public static function handle(Closure $next)
    {
        echo "开启 session，获取数据<br>";
        $next();
        echo "保存session，关闭session<br>";
    }
}
class AddQueuedCookiesToResponse implements Middleware
{
    public static function handle(Closure $next)
    {
        $next();
        echo "添加下一次请求需要的cookie<br>";
    }
}
class EncryptCookies implements Middleware
{
    public static function handle(Closure $next)
    {
        echo "对输入请求的cookie进行解密<br>";
        $next();
        echo "对输出响应的cookie进行加密<br>";
    }
}
class CheckForMaintenanceMode implements Middleware
{
    public static function handle(Closure $next)
    {
        echo "确定当前程序处于维护状态<br>";
        $next();
    }
}
function getSlice()
{
    return function($stack, $pipe)
    {
        return function() use ($stack, $pipe)
        {
            return $pipe::handle($stack);
        };
    };
}
function then()
{
    $pipes = [
        "CheckForMaintenanceMode",
        "EncryptCookies",
        "AddQueuedCookiesToResponse",
        "StartSession",
        "ShareErrorsFromSession",
        "VerifyCsrfToken"
    ];
    $firstSlice = function(){
        echo "请求向路由器传递，返回响应<br>";
    };
    $pipes = array_reverse($pipes); //  返回一个单元顺序相反的数组
    call_user_func(
        array_reduce($pipes, getSlice(), $firstSlice) // 用回调函数迭代地将数组简化为单一的值
    );
}
then();

*/

/*interface Step
{
    public static function go(Closure $next);
}
class FirstStep implements Step
{
    public static function go(Closure $next)
    {
        echo "开启session，获取数据<br>";
        $next();
        echo "保存数据关闭session<br>";
    }
}
function goFun($step, $className)
{
    return function() use($step, $className)
    {
        return $className::go($step);
    };
}
function then()
{
    $steps = ["FirstStep"];
    $prepare = function() {
        echo "请求向路由器传递，返回响应<br>";
    };
    $go = array_reduce($steps, "goFun", $prepare);
    $go();
}
then();
*/
// 请求处理管道
// /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php




/*
// 提供像访问数组一样访问对象的能力的接口
class obj implements arrayaccess {
    private $container = array();
    public function __construct() {
        $this->container = array(
            "one"   => 1,
            "two"   => 2,
            "three" => 3,
        );
    }
    // 设置一个偏移位置的值
    public function offsetSet($offset, $value) {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }
    // 检查一个偏移位置是否存在
    public function offsetExists($offset) {
        return isset($this->container[$offset]);
    }
    // 复位一个偏移位置的值
    public function offsetUnset($offset) {
        unset($this->container[$offset]);
    }
    // 获取一个偏移位置的值
    public function offsetGet($offset) {
        return isset($this->container[$offset]) ? $this->container[$offset] : null;
    }
}

$obj = new obj;

echo '<pre>';
var_dump(isset($obj["two"]));
var_dump($obj["two"]);
unset($obj["two"]);
var_dump(isset($obj["two"]));
$obj["two"] = "A value";
var_dump($obj["two"]);
$obj[] = 'Append 1';
$obj[] = 'Append 2';
$obj[] = 'Append 3';
print_r($obj);
*/







// p($_SERVER);



// class mdSession { /*        使用:    服务器A，服务器B,在A的index.php登陆,在B里建立一个接收SESSION的文件，例如ses_get.php    A的index.php做如下修改    最开始加上session_start();     里，任意一个地方写上:mdSession::_set('B/ses_get.php')    而ses_get.php则在开头写上mdSession::_get();    @作者:surfchen@gmail.com http://www.surfchen.org/    */
//     function mdSession() {
//     }
//     function set($urls) {
//         if (!is_array($urls)) {
//             $urls = array(
//                 $urls
//             );
//         }
//         foreach ($urls as $value) {
//             echo '';
//         }
//         return true;
//     }
//     function get() {
//         session_id($_SERVER['QUERY_STRING']);
//         session_start();
//         return true;
//     }
//     function _set($urls) {
//         $obj = new mdSession();
//         return $obj->set($urls);
//     }
//     function _get() {
//         $obj = new mdSession();
//         return $obj->get();
//     }
// }






/*function foo()
{
    echo '<pre>';
    $numargs = func_num_args(); // 打印参数数量
    print_r($numargs);
    if ($numargs >= 2) {
        print_r(func_get_arg(1)); // 打印某个参数的值
    }
    $arg_list = func_get_args(); // 打印参数列表
    print_r($arg_list);
}

foo(1, '第二个参数', 3, 4, 5, 6, 7, 8);

*/


// property_exists() // 检查对象或类是否具有该属性 






// Closure 类
// Closure::__construct — 用于禁止实例化的构造函数
// Closure::bind ( Closure $closure , object $newthis [, mixed $newscope  = 'static' ] ) — 复制一个闭包，绑定指定的$this对象和类作用域。
// Closure::bindTo( object $newthis [, mixed $newscope  = 'static' ] ) — 复制当前闭包对象，绑定指定的$this对象和类作用域。



// class A {
//     private static $sfoo = 1;
//     private $ifoo = 2;
// }
// $cl1 = static function() {
//     return A::$sfoo;
// };
// $cl2 = function() {
//     return $this->ifoo;
// };

// $bcl1 = Closure::bind($cl1, null, 'A');
// // $bcl2 = Closure::bind($cl2, new A(), 'A');
// echo $bcl1(), "\n";
// // echo $bcl2(), "\n";



trait MetaTrait
{
     private $methods = [];
     public function addMethod($methodName, $methodCallable)
     {
         if (!is_callable($methodCallable)) { // 检测参数是否为合法的可调用结构 
             throw new InvalidArgumentException('Second param must be callable');
         }
         $this->methods[$methodName] = Closure::bind($methodCallable, $this, get_class());
     }
     // 调用不存在的动态方法
     public function __call($methodName, array $args)
     {
         if (isset($this->methods[$methodName])) {
             return call_user_func_array($this->methods[$methodName], $args);
         }
         throw RunTimeException('There is no method with the given name to call');
     }
     public static function  editMethod($methodName, $methodCallable)
     {
         $this->methods[$methodName] = Closure::bind($methodCallable, null, 'HackThursday');
     }
     // 调用不存在的额静态方法
     public static function __callStatic($a, $b)
     {
        // p($a);
        // p($b);
     }
 }
 class HackThursday {
     use MetaTrait;
     private $dayOfWeek = 'Thursday';
     private static $two = 'two';
 }


$test = new HackThursday();
$test->addMethod('when', function () {
     return $this->dayOfWeek;
 });
 echo $test->when();
echo '<br>';


HackThursday::editMethod('when', function () {
     return self::$two;
     // exit;
 });
 // echo $test->when();



-------------------------------------------------
// $callback=function(){ 
//  return "aa"; 
// }; 
// echo $callback(); 
// function foo()
// {
//     echo '<pre>';
//     $numargs = func_num_args(); // 打印参数数量
//     print_r($numargs);
//     if ($numargs >= 2) {
//         print_r(func_get_arg(1)); // 打印某个参数的值
//     }
//     $arg_list = func_get_args(); // 打印参数列表
//     print_r($arg_list);
// }

// foo(1, '第二个参数', 3, 4, 5, 6, 7, 8);


----------------------------------------------------------------------
